argss <- commandArgs(trailingOnly = TRUE)

print(argss)
row_num=length(argss)

# out_name=paste(dataa, 'lorenz.pdf', sep='.')

pdf('cov.multi.pdf', width=6, height=2*row_num)


opar=par(no.readonly=T)

# par(mfrow=c(nrow,1), ann=F, xaxs='i', yaxs='i')


# xaxt='n' no display x axis
# bty='n' no display box; #box type
par(mfrow=c(row_num,1), ann=F, xaxt='n', yaxt='n', bty='n')

xlim=c(0,1)
# ylim=c(0,1)

# plot(NA, type='n', xlim=xlim, ylim=ylim, cex.axis=.5)

cols=rainbow(row_num)

for (i in 1:length(argss)) {
	y=read.table(argss[i])
	y=y$V1/sum(y$V1)
	xlen=length(y)
	x=1:xlen/xlen
	ylim=c(0, 1.2*max(predict(loess(y~x))))
	plot(NA, xlim=xlim, ylim=ylim)
	title(ylab=argss[i])
	polygon( c(x, x[xlen], x[1]), c(y, 0, 0), col=cols[i], border=cols[i])

}



# title_main=paste("Coverage")

# title(main=title_main, xlab="Cumulative fraction of genome", ylab="Cumulative fraction of total reads")

# legend("topleft", inset=.05, lty=c(1,1,1), c(gini_str, gini_simu_str), col=c('blue', 'gray'))


dev.off()

q(save = "yes", status = 0, runLast = FALSE)